package com.hanyizhu.demostore.service.impl;

import com.hanyizhu.demostore.entity.District;
import com.hanyizhu.demostore.mapper.DistrictMapper;
import com.hanyizhu.demostore.service.IDistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lenovo
 */
@Service //@Service注解:将当前类的对象交给Spring来管理,自动创建对象以及对象管理
public class DistrictServiceImpl implements IDistrictService {
    @Autowired
    private DistrictMapper districtMapper;

    @Override
    public List<District> getByParent(String parent) {
        List<District> list = districtMapper.findByParent(parent);
        //在进行网络数据传输时,为了尽量避免无效数据的传递,可以将无效数据设置为null
        for (District d:list
             ) {
            d.setId(null);
            d.setParent(null);
        }
        return list;
    }

    @Override
    public String getNameByCode(String code) {
        return districtMapper.findNameByCode(code);
    }
}
